def match_ios_conv(data, save_file=None):
	out_size = data.shape[0]
	in_size = data.shape[1]
	height = data.shape[2]
	width = data.shape[3]
	# for o in range(out_size):
	# 	for h in range(height):
	# 		for w in range(width):
	# 			for i in range(in_size):
	# 				# index = ((o * in_size + i) * height + h) * width + w
	# 				print str(data[o, i, h, w]) + ',',
	# 			if in_size % 4 == 1:
	# 				print '0.0, 0.0, 0.0, ',
	# 			elif in_size % 4 == 2:
	# 				print '0.0, 0.0, ',
	# 			elif in_size % 4 == 3:
	# 				print '0.0, ',
	# 			print
	# 		print
	# 	# print
	# print

	if save_file:
		with open(save_file, 'w') as f:
			for o in range(out_size):
				for h in range(height):
					for w in range(width):
						for i in range(in_size):
							# index = ((o * in_size + i) * height + h) * width + w
							# print str(data[o, i, h, w]) + ',',
							f.write(str(data[o, i, h, w]) + ',')
						if in_size % 4 == 1:
							# print '0.0, 0.0, 0.0, ',
							f.write('0.0, 0.0, 0.0, ')
						elif in_size % 4 == 2:
							# print '0.0, 0.0, ',
							f.write('0.0, 0.0, ')
						elif in_size % 4 == 3:
							# print '0.0, ',
							f.write('0.0, ')
						# print
						f.write('\n')
					# print
					f.write('\n')
			# print
			f.write('\n')


def save_bias_file(data, filename):
	data_len = data.size
	with open(filename, 'w') as f:
		for i in range(data_len):
			f.write(str(data[i]) + ', ')
		if data_len % 4 == 1:
			f.write('0.0, 0.0, 0.0')
		elif data_len % 4 == 2:
			f.write('0.0, 0.0')
		elif data_len % 4 == 3:
			f.write('0.0')
		f.write('\n')


def save_innerproduct_file(data, channels, height, width, filename):
	with open(filename, 'w') as f:
		for o in range(data.shape[0]):
			for h in range(height):
				for w in range(width):
					for c in range(channels):
						# print str(data[o, (c * height + h) * width + w]) + ', ',
						f.write(str(data[o, (c * height + h) * width + w]) + ', ')
					if channels % 4 == 1:
						f.write('0.0, 0.0, 0.0')
					elif channels % 4 == 2:
						f.write('0.0, 0.0')
					elif channels % 4 == 3:
						f.write('0.0')
					# print
					f.write('\n')
		# print
		f.write('\n')

def match_ios_innerproduct(data, channels, height, width):
	for o in range(data.shape[0]):
		for h in range(height):
			for w in range(width):
				for c in range(channels):
					print str(data[o, (c * height + h) * width + w]) + ', ',
				# print
	print


def print_value(data):
	data = data.reshape(data.size)
	for i in range(data.size):
		print str(data[i]) + ', ',
	print
